{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  from ._conv import register_converters as _register_converters\n",
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "from keras.datasets import mnist\n",
    "from keras.layers import Flatten, Conv2D, MaxPool2D, Dense\n",
    "from keras.models import Sequential\n",
    "from keras.optimizers import SGD\n",
    "from keras.utils import plot_model, to_categorical\n",
    "\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "(x_train, y_train), (x_test, y_test) = mnist.load_data()\n",
    "#数据变成TensorFow为Backend的形式\n",
    "x_train=x_train.reshape(60000,28,28,1)\n",
    "x_test=x_test.reshape(10000,28,28,1)\n",
    "#把标签变成one-hot编码的形式\n",
    "y_train=to_categorical(y_train,num_classes=10)\n",
    "y_test=to_categorical(y_test,num_classes=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "conv2d_1 (Conv2D)            (None, 24, 24, 6)         156       \n",
      "_________________________________________________________________\n",
      "max_pooling2d_1 (MaxPooling2 (None, 12, 12, 6)         0         \n",
      "_________________________________________________________________\n",
      "conv2d_2 (Conv2D)            (None, 8, 8, 16)          2416      \n",
      "_________________________________________________________________\n",
      "max_pooling2d_2 (MaxPooling2 (None, 4, 4, 16)          0         \n",
      "_________________________________________________________________\n",
      "flatten_1 (Flatten)          (None, 256)               0         \n",
      "_________________________________________________________________\n",
      "dense_1 (Dense)              (None, 120)               30840     \n",
      "_________________________________________________________________\n",
      "dense_2 (Dense)              (None, 84)                10164     \n",
      "_________________________________________________________________\n",
      "dense_3 (Dense)              (None, 10)                850       \n",
      "=================================================================\n",
      "Total params: 44,426\n",
      "Trainable params: 44,426\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "# 构建LeNet-5网络\n",
    "model = Sequential()\n",
    "model.add(Conv2D(input_shape = (28,28,1), filters=6, kernel_size=(5,5), padding='valid', activation='tanh'))\n",
    "model.add(MaxPool2D(pool_size=(2,2), strides=2))\n",
    "model.add(Conv2D(input_shape=(14,14,6), filters=16, kernel_size=(5,5), padding='valid', activation='tanh'))\n",
    "model.add(MaxPool2D(pool_size=(2,2), strides=2))\n",
    "model.add(Flatten())\n",
    "model.add(Dense(120, activation='tanh'))\n",
    "model.add(Dense(84, activation='tanh'))\n",
    "model.add(Dense(10, activation='softmax'))\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/30\n",
      "60000/60000 [==============================] - 11s 189us/step - loss: 0.9287 - acc: 0.7676\n",
      "Epoch 2/30\n",
      "60000/60000 [==============================] - 12s 194us/step - loss: 0.3284 - acc: 0.9180\n",
      "Epoch 3/30\n",
      "60000/60000 [==============================] - 11s 185us/step - loss: 0.2356 - acc: 0.9375\n",
      "Epoch 4/30\n",
      "60000/60000 [==============================] - 11s 186us/step - loss: 0.1897 - acc: 0.9479\n",
      "Epoch 5/30\n",
      "60000/60000 [==============================] - 11s 191us/step - loss: 0.1618 - acc: 0.9543\n",
      "Epoch 6/30\n",
      "60000/60000 [==============================] - 11s 187us/step - loss: 0.1432 - acc: 0.9591\n",
      "Epoch 7/30\n",
      "60000/60000 [==============================] - 11s 188us/step - loss: 0.1308 - acc: 0.9622\n",
      "Epoch 8/30\n",
      "60000/60000 [==============================] - 13s 209us/step - loss: 0.1185 - acc: 0.9658\n",
      "Epoch 9/30\n",
      "60000/60000 [==============================] - 13s 213us/step - loss: 0.1121 - acc: 0.9675\n",
      "Epoch 10/30\n",
      "60000/60000 [==============================] - 11s 184us/step - loss: 0.1036 - acc: 0.9697\n",
      "Epoch 11/30\n",
      "60000/60000 [==============================] - 11s 184us/step - loss: 0.0983 - acc: 0.9713\n",
      "Epoch 12/30\n",
      "60000/60000 [==============================] - 11s 184us/step - loss: 0.0936 - acc: 0.9722\n",
      "Epoch 13/30\n",
      "60000/60000 [==============================] - 11s 183us/step - loss: 0.0895 - acc: 0.9736\n",
      "Epoch 14/30\n",
      "60000/60000 [==============================] - 11s 188us/step - loss: 0.0867 - acc: 0.9742\n",
      "Epoch 15/30\n",
      "60000/60000 [==============================] - 11s 177us/step - loss: 0.0817 - acc: 0.9757\n",
      "Epoch 16/30\n",
      "60000/60000 [==============================] - 11s 179us/step - loss: 0.0784 - acc: 0.9769\n",
      "Epoch 17/30\n",
      "60000/60000 [==============================] - 11s 182us/step - loss: 0.0765 - acc: 0.9775\n",
      "Epoch 18/30\n",
      "60000/60000 [==============================] - 11s 182us/step - loss: 0.0736 - acc: 0.9781\n",
      "Epoch 19/30\n",
      "60000/60000 [==============================] - 11s 190us/step - loss: 0.0707 - acc: 0.9792\n",
      "Epoch 20/30\n",
      "60000/60000 [==============================] - 11s 183us/step - loss: 0.0691 - acc: 0.9797\n",
      "Epoch 21/30\n",
      "60000/60000 [==============================] - 11s 187us/step - loss: 0.0677 - acc: 0.9803\n",
      "Epoch 22/30\n",
      "60000/60000 [==============================] - 11s 179us/step - loss: 0.0658 - acc: 0.9803\n",
      "Epoch 23/30\n",
      "60000/60000 [==============================] - 11s 182us/step - loss: 0.0641 - acc: 0.9812\n",
      "Epoch 24/30\n",
      "60000/60000 [==============================] - 11s 185us/step - loss: 0.0627 - acc: 0.9818\n",
      "Epoch 25/30\n",
      "60000/60000 [==============================] - 11s 179us/step - loss: 0.0610 - acc: 0.9824\n",
      "Epoch 26/30\n",
      "60000/60000 [==============================] - 11s 180us/step - loss: 0.0589 - acc: 0.9827\n",
      "Epoch 27/30\n",
      "60000/60000 [==============================] - 11s 179us/step - loss: 0.0576 - acc: 0.9829\n",
      "Epoch 28/30\n",
      "60000/60000 [==============================] - 11s 183us/step - loss: 0.0567 - acc: 0.9835\n",
      "Epoch 29/30\n",
      "60000/60000 [==============================] - 11s 181us/step - loss: 0.0556 - acc: 0.9837\n",
      "Epoch 30/30\n",
      "60000/60000 [==============================] - 12s 198us/step - loss: 0.0535 - acc: 0.9845\n",
      "dict_keys(['loss', 'acc'])\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEWCAYAAACJ0YulAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAIABJREFUeJzt3XmcHHWd//HXp++5cszkgiSYBMMtCZBwqBwKKIhcrgviqhwKXnjhxW9lldXdn7e76rJAVlFQAQOCZpXjR5RDNBwBgkC4QgAzIReTayZzdvfn90dV9/RMJpnOJD090/1+Ph796Oqq6upPzST1nvp+q75t7o6IiAhApNwFiIjIyKFQEBGRPIWCiIjkKRRERCRPoSAiInkKBRERyVMoSFUxs5+b2b8Vue4rZnZSqWsSGUkUCiIikqdQEBmFzCxW7hqkMikUZMQJm22+aGZ/M7NtZvZTM5tsZneaWauZLTaz8QXrn2Fmz5jZZjO7z8wOLFh2mJk9Hr7v10Cq32e928yWhe/9q5kdWmSNp5nZE2a21cxWmdmV/Za/Ndze5nD5BeH8GjP7vpm9amZbzOzBcN4JZtY8wM/hpHD6SjO71cx+aWZbgQvM7EgzWxJ+xhoz+y8zSxS8/2Azu8fMNprZOjP7ZzObYmbtZtZUsN7hZrbBzOLF7LtUNoWCjFT/AJwM7AecDtwJ/DMwkeDf7acBzGw/4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geBa83s6+E2/nEYd0NkSDRKqkiRzKzN3evLXYdIKan5SERE8nSmICIieTpTEBGRPIWCiIjkKRRERCRPoSAiInkKBRERyfv/HoLKapv3gZIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "model.compile(loss='categorical_crossentropy', optimizer=SGD(lr=0.01), metrics=['accuracy'])\n",
    "history = model.fit(x_train, y_train, batch_size=128, epochs=30)\n",
    "print(history.history.keys())\n",
    "# summarize history for accuracy\n",
    "plt.plot(history.history['loss'])\n",
    "plt.plot(history.history['acc'])\n",
    "plt.title('model accuracy')\n",
    "plt.ylabel('accuracy')\n",
    "plt.xlabel('epoch')\n",
    "plt.legend(['loss','acc'], loc='upper left')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10000/10000 [==============================] - 1s 133us/step\n",
      "Testing Loss: 0.056708887127041814\n",
      "Testing Accuracy of: 0.9825\n"
     ]
    }
   ],
   "source": [
    "score=model.evaluate(x_test,y_test)\n",
    "print(\"Testing Loss:\", score[0])\n",
    "print(\"Testing Accuracy of:\", score[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
